package com.dman.multi.cmd;

import org.apache.pivot.collections.List;
import org.apache.pivot.wtk.TreeView;
import org.apache.pivot.wtk.content.TreeNode;

import com.dman.multi.core.Download;
import com.dman.multi.core.DownloadState;

public class GUIDownloadStateCommand implements Command {
	
	private List<Download> downloadList;
	private TreeView treeView;

	public GUIDownloadStateCommand(List<Download> downloadList, TreeView treeView) {
		this.downloadList = downloadList;
		this.treeView = treeView;
	}

	@Override
	public void execute() {
		TreeNode tn = (TreeNode) treeView.getSelectedNode();
		String text = tn.getText().toUpperCase();
		DownloadState filterType = DownloadState.valueOf(text);
		synchronized (downloadList) {
			for(Download d: downloadList){
				d.setVisible(false);
				if(d.getDownloadState() == filterType){
					d.setVisible(true);
				}
			}
		}
	}

}
